home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / imap-3.0 / ANSI / c-client / nntp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-10  |  3.2 KB  |  93 lines

  1. /*
  2.  * Program:    Network News Transfer Protocol (NNTP) routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    10 February 1992
  13.  * Last Edited:    10 June 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington.
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notices appear in all copies and that both the
  20.  * above copyright notices and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  30.  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN
  32.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include "mail.h"
  40. #include "osdep.h"
  41. #include "smtp.h"
  42. #include "nntp.h"
  43. #include "rfc822.h"
  44. #include "misc.h"
  45.  
  46. /* Network News Transfer Protocol open connection
  47.  * Accepts: service host list
  48.  *        initial debugging flag
  49.  * Returns: T on success, NIL on failure
  50.  */
  51.  
  52. SMTPSTREAM *nntp_open (char **hostlist,long debug)
  53. {
  54.   SMTPSTREAM *stream = NIL;
  55.   void *tcpstream;
  56.   if (!(hostlist && *hostlist)) mm_log ("Missing NNTP service host",ERROR);
  57.   else do {            /* try to open connection */
  58.     if (tcpstream = tcp_open (*hostlist,NNTPTCPPORT)) {
  59.       stream = (SMTPSTREAM *) fs_get (sizeof (SMTPSTREAM));
  60.       stream->tcpstream = tcpstream;
  61.       stream->debug = debug;
  62.       stream->reply = NIL;
  63.                 /* get NNTP greeting */
  64.       if (smtp_reply (stream) == NNTPGREET) return stream;
  65.       smtp_close (stream);    /* otherwise punt stream */
  66.     }
  67.   } while (*++hostlist);    /* try next server */
  68.   return NIL;
  69. }
  70.  
  71. /* Network News Transfer Protocol deliver news
  72.  * Accepts: stream
  73.  *        message envelope
  74.  *        message body
  75.  * Returns: T on success, NIL on failure
  76.  */
  77.  
  78. long nntp_mail (SMTPSTREAM *stream,ENVELOPE *env,BODY *body)
  79. {
  80.   char tmp[8*MAILTMPLEN];
  81.                 /* negotiate post command */
  82.   if (!(smtp_send (stream,"POST",NIL) == NNTPREADY)) return NIL;
  83.                 /* set up error in case failure */
  84.   smtp_fake (stream,SMTPSOFTFATAL,"NNTP connection went away!");
  85.                 /* RFC-1036 requires this cretinism */
  86.   sprintf (tmp,"Path: %s!%s\015\012",tcp_localhost (stream->tcpstream),
  87.        env->from ? env->from->mailbox : "foo");
  88.                 /* output data, return success status */
  89.   return tcp_soutr (stream->tcpstream,tmp) &&
  90.     rfc822_output (tmp,env,body,smtp_soutr,stream->tcpstream) &&
  91.       (smtp_send (stream,".",NIL) == NNTPOK);
  92. }
  93.